{extend name='bus@public/index'}
{block name="css"}{/block}
{block name="main"}
<div class="form  mr-3" style="padding-top:20px" ng-controller="BasicsInfoController">
    <div class="form-row">
<!--        <div class="form-inline col-12 form-group">-->
<!--            <label class="col-3" for="pid">上级</label>-->
<!--            <select class="form-control col-8" name="pid" id="pid" ng-model="model.pid" ng-options="o.id as o.name for o in department">-->
<!--            </select>-->
<!--        </div>-->
        <div class="form-inline col-12 form-group">
            <label class="col-3" for="name">名称</label>
            <input type="text" class="form-control col-8" id="name" name="name" autocomplete="off" ng-model="model.name" placeholder="请输入部门名称">
        </div>
        <div class="form-inline col-12 form-group">
            <label class="col-3" for="status">状态</label>
            <select class="form-control col-8" name="status" id="status" ng-model="model.status" ng-options="o.id as o.name for o in status"></select>
        </div>
        <div class="form-inline col-12 form-group">
            <label class="col-3" for="remark">备注</label>
            <input type="text" class="form-control col-8" id="remark" name="remark" autocomplete="off" ng-model="model.remark" placeholder="请输入备注">
        </div>

    </div>

    <div class="text-center mt-2">
        <input type='hidden' value='{$Think.get.id}' name='id'/>
        <button type="button" class="btn btn-secondary btn-cancel"> 取消</button>
        <button type="button" class="btn btn-primary ml-2" ng-click="Submit()"> 保存</button>
    </div>
</div>
{/block}
{block name="script"}
<script>
    let PageConfig = {
        InfoUrl:'/admin/department/info_data',
        SubmitUrl:'/admin/department/post_data'
    }
</script>

<script>
    app.controller("BasicsInfoController", function($scope, $http, selectFactory,dataFactory) {
        //绑定下拉框
        $scope.department = [];
        $scope.status = [];
        dataFactory.SelectDepartment().then(function (data) {
            $scope.department = data;
        });
        dataFactory.SelectStatus().then(function (data) {
            $scope.status = data;
        });
        $scope.model = {
            id:$("[name='id']").val(),
            name: '',
            status: '正常',
            remark: '',
        };
        //编辑加载数据
        $scope.LoadInfo = function(){
            if($scope.model.id != 0){
                let index = layer.load(2 ,{ icon: 2 ,shade: 0.1 });
                $http({
                    method: 'GET',
                    url: PageConfig.InfoUrl,
                    cache: false,
                    params: { id: $scope.model.id }
                }).success(function (result, status, headers, config) {
                    layer.close(index);
                    if (result.code == 0) {
                        $scope.model = result.data;
                    }
                }).error(function (result, status, headers, config) {
                    layer.close(index);
                    oob.show({code:-1,msg:"请求过程中发生异常"});
                });
            }
        };
        //保存数据
        $scope.Submit = function(){
            let index = layer.load(2 ,{ icon: 2 ,shade: 0.1 });
            $http({
                method: 'POST',
                url: PageConfig.SubmitUrl,
                cache: false,
                params: $scope.model
            }).success(function (result, status, headers, config) {
                oob.show(result,function () {
                    layer.close(index);
                    if (result.code == 0) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.bind();
                    }
                });
            }).error(function (result, status, headers, config) {
                layer.close(index);
                oob.show({code:-1,msg:"请求过程中发生异常"});
            });
        };
        $(function () {
            $scope.LoadInfo();
        });
    });
</script>
{/block}
{/block}